<?php
namespace Home\Controller;
use Think\Controller;
use Think\Page;
class IndexController extends CommonController {
    public function index(){
    	$this -> assign('titile','首页');
    	$mod = M('article');
        $page = new Page($mod ->count(),6);                       
                        $page->setConfig('prev','上一页');
                        $page->setConfig('next','下一页');                 
                        //分页链接
                        $url = $page->show();
                        $this -> assign('url',$url);    
    	$article_data = $mod ->field('article_id,title,add_time,description,article_status')->order('article_id desc') ->limit($page->firstRow,$page->listRows)->select(); 
        $user = M('users') -> field('sum(user_money1) as user_money1,sum(user_money3) as user_money3,sum(option_num) as option_num,sum(user_money2) as user_money2,sum(user_money4) as user_money4,sum(cishan_money) as cishan') -> where('user_id=%d',[$_SESSION['users']['user_id']]) -> find();   	
    	$this ->assign('status',$article_data[0]);
        $this -> assign('article',$article_data);
        $this -> assign('user',$user);
        
        $this->display('');
    }
    public function content(){
    	$this -> assign('title','公告详情');
    	$mod = M('article');
        $article_last_id = $mod -> order('article_id desc') -> find()['article_id'];
       
        if(empty(I('get.id'))){
             $id = $article_last_id;
        }else{
             $id = I('get.id');
        }
       
    	$article = $mod -> where('article_id = "%s" ',$id)->find();
    	$this -> assign('article',$article);
    	$this -> display('');
    }

}